﻿using MediatR;
using SheepCultivation.Common.Domain;
using SheepCultivation.Common.Dto;
using SheepCultivation.Common.Infrastructure.Interface;
using SheepCultivation.Enum;
using System.Collections;
using System.Collections.Generic;

namespace SheepCultivation.API.AddliCation.DepartmentW
{
    public class IndustrySeachHandler : IRequestHandler<IndustrySeachCommon, Result>
    {
        public readonly IBaseRepository<Industry> IndustryRepository;

        public IndustrySeachHandler(IBaseRepository<Industry> industryRepository)
        {
            IndustryRepository = industryRepository;
        }

        public async Task<Result> Handle(IndustrySeachCommon request, CancellationToken cancellationToken)
        {
            var res = new Result() { Code = (int)CommonEnumCode.error };
            try
            {

                if (request.IndustryId == -1)
                {
                    var list = IndustryRepository.GetAll().Where(x => x.Pid == 0).ToList();
                    res.Data = list;
                }
                else
                {
                    var list = IndustryRepository.GetAll().Where(x => x.Pid == request.IndustryId).ToList();
                    res.Data = list;
                }


            }
            catch (Exception)
            {

                throw;
            }
            return res;
        }

    }
}
